#!/usr/bin/env bash

# Stop plugin service
sudo launchctl remove tw.com.lumens.DocumentCamera

# Preferences
rm -f ~/Library/Preferences/tw.com.Lumens.WirelessDC2.plist
rm -f ~/Library/Preferences/tw.com.Lumens.WirelessDC1.plist
rm -f ~/Library/Preferences/tw.com.lumens.Ladibug.plist
rm -f ~/Library/Preferences/tw.com.lumens.LumensDocumentCameraDC122.plist

# Application
rm -rf /Applications/Ladibug.app

# Plugin
rm -rf /Library/CoreMediaIO/Plug-Ins/DAL/LumensDocumentCamera.plugin
rm -rf /Library/LaunchDaemons/tw.com.lumens.DocumentCamera.plist

# QuickTime
ls -d /Library/QuickTime/Lumens*.component | xargs rm -rf

# Driver
ls -d /System/Library/Extensions/Lumens*.kext | xargs rm -rf
ls -d /Library/Extensions/Lumens*.kext | xargs rm -rf

# Receipts
ls /var/db/receipts/tw.com.lumens.pkgs* | xargs rm -rf

# Receipts (Legacy packages)
ls /var/db/receipts/tw.com.lumens.ladibug* | xargs rm -rf

# Receipts (Generated before osx 10.6)
rm -rf /Library/Receipts/lumenswirelessdc2.pkg
rm -rf ~/Library/Receipts/lumenswirelessdc2.pkg

rm -rf /Library/Receipts/lumensdocumentcameradc170.pkg
rm -rf ~/Library/Receipts/lumensdocumentcameradc170.pkg

rm -rf /Library/Receipts/lumensdocumentcameradc122.pkg
rm -rf ~/Library/Receipts/lumensdocumentcameradc122.pkg

rm -rf /Library/Receipts/lumenswirelessdc1.pkg
rm -rf ~/Library/Receipts/lumenswirelessdc1.pkg

rm -rf /Library/Receipts/lumensdocumentcamera.pkg
rm -rf ~/Library/Receipts/lumensdocumentcamera.pkg

rm -rf /Library/Receipts/lumensdigitizer.pkg
rm -rf ~/Library/Receipts/lumensdigitizer.pkg

rm -rf /Library/Receipts/lumensdc260msdc.pkg
rm -rf ~/Library/Receipts/lumensdc260msdc.pkg

rm -rf /Library/Receipts/lumensaudiodriver.pkg
rm -rf ~/Library/Receipts/lumensaudiodriver.pkg

rm -rf /Library/Receipts/ladibug.pkg
rm -rf ~/Library/Receipts/ladibug.pkg

rm -rf /Library/Receipts/ladibug20Preflight.pkg
rm -rf ~/Library/Receipts/ladibug20Preflight.pkg

# For macOS 10.15 above
# Clear permissions if available
sudo tccutil reset All tw.com.lumens.Ladibug || true
